package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Comment;
import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private CommentsService commentsService;

    @GetMapping(value = "/likes",name = "点赞列表")
    public ResponseEntity likes( @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10")Integer pagesize){

        return commentsService.queryLikesOrLovesOrComments(page,pagesize,1);
    }
    @GetMapping(value = "/loves",name = "喜欢列表")
    public ResponseEntity loves( @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10")Integer pagesize){

        return commentsService.queryLikesOrLovesOrComments(page,pagesize,3);
    }
    @GetMapping(value = "/comments",name = "评论列表")
    public ResponseEntity comments( @RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10")Integer pagesize){

        return commentsService.queryLikesOrLovesOrComments(page,pagesize,2);
    }

    @PostMapping(value = "/contacts",name = "聊一下成为好友")
    public ResponseEntity beFriends(@RequestBody Map map){

        Long userId = Long.parseLong(map.get("userId").toString());
        return commentsService.beFriends(userId);
    }


}
